//
//  QYModifyInfoCell.m
//  QingYue
//
//  Created by Zheng on 2017/5/23.
//  Copyright © 2017年 com.lanou.product_A. All rights reserved.
//

#import "QYModifyInfoCell.h"

@implementation QYModifyInfoCell

- (instancetype)initWithModifyInfoStyle:(QYModifyInfoCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
    if (self) {

        switch (style) {
            case QYModifyInfoCellStyleHeadPortrait: {
                self.titleLbl.text = @"头像";
                self.modifyInfoStyle = QYModifyInfoCellStyleHeadPortrait;
                self.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
                self.selectionStyle = UITableViewCellSelectionStyleNone;
                [self.contentView addSubview:self.iconImgv];
            }
                break;
            case QYModifyInfoCellStyleNickname: {
                self.titleLbl.text = @"昵称";
                self.modifyInfoStyle = QYModifyInfoCellStyleNickname;
                self.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
                self.selectionStyle = UITableViewCellSelectionStyleDefault;
                [self.contentView addSubview:self.detailLbl];
                
                
            }
                break;
            case QYModifyInfoCellStyleReaderCard: {
                self.titleLbl.text = @"读者证号";
                self.modifyInfoStyle = QYModifyInfoCellStyleReaderCard;
                self.accessoryType = UITableViewCellAccessoryNone;
                self.selectionStyle = UITableViewCellSelectionStyleNone;
                [self.contentView addSubview:self.detailLbl];
                
                self.detailLbl.text = @"651418954821316426";
            }
                break;
            default:
                break;
        }
        
        [self.contentView addSubview:self.titleLbl];
        
        [self layoutSubview];
    }
    return self;
}

#pragma mark - layout subview
- (void)layoutSubview {
    [_titleLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.top.bottom.equalTo(self);
    }];
    
    if (_iconImgv) {
        [_iconImgv mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self);
            make.width.height.mas_equalTo(50);
            make.right.equalTo(self.contentView.mas_right);
        }];
    }
    
    if (_detailLbl) {
        CGFloat rightLayout = (self.modifyInfoStyle == QYModifyInfoCellStyleNickname)? 0: -15;
        [_detailLbl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.bottom.equalTo(self);
            make.right.equalTo(self.contentView.mas_right).offset(rightLayout);
        }];
    }
}

#pragma mark - Lazy Load
- (UILabel *)titleLbl {
    if (!_titleLbl) {
        _titleLbl = [[UILabel alloc] init];
        _titleLbl.font = Font(15);
    }
    return _titleLbl;
}

- (UIImageView *)iconImgv {
    if (!_iconImgv) {
        _iconImgv = [[UIImageView alloc] init];
        _iconImgv.layer.cornerRadius = 25;
        _iconImgv.layer.masksToBounds = YES;
        _iconImgv.image = [UIImage imageNamed:@"默认用户头像"];
    }
    return _iconImgv;
}

- (UILabel *)detailLbl {
    if (!_detailLbl) {
        _detailLbl = [[UILabel alloc] init];
        _detailLbl.font = Font(15);
    }
    return _detailLbl;
}

@end
